<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    //思路一
    // function replaceSpace(str){
    //     return str.replace(" ","%20");
    // }
    // console.log(replaceSpace("A B"))

    //思路二
    function replaceSpace(str){
        debugger
        let P1 = ""
        for (let i = 0; i < str.length; i++) {
            if(str[i] === " "){
                P1  += '%20'
            }else{
                P1 += str[i]
            }
        }
        return P1
    }
    console.log(replaceSpace("A B"))
</script>
</html>
